<?php

$params = call_user_func_array(['yii\helpers\ArrayHelper', 'merge'], [
    require(__DIR__ . '/../../../common/config/params.php'),
    require(__DIR__ . '/../../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
]);

return [
    'id' => 'app-paymch',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'paymch\controllers',
    'components' => [
        'response' => [
            'class' => 'yii\web\Response',
            'format' => \yii\web\Response::FORMAT_JSON,
            'on beforeSend' => function ($event) {
                $sender = $event->sender;
                $responseData = [
                    'code' => $sender->statusCode,
                    'msg' => 'Success',
                ];
                if ($sender->statusCode == 200) {
                    $responseData['data'] = $sender->data;
                } else {
                    $responseData['msg'] = $sender->data['message'];
                }
                $sender->statusCode = 200;
                $sender->data = $responseData;
            },
        ],
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['info', 'error', 'warning'],
                    'logFile' => '@runtime/logs/' . date('Ym/') . 'payment_' . date('d') . '.log',
                    'logVars' => ['_GET', '_POST'],
                    'categories' => ['payment'],
                ]
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ],
        ],
    ],
    'params' => $params,
];

